import { useI18n } from '/@/hooks/web/useI18n';
import { BasicColumn, BasicTableProps, FormProps } from '/@/components/Table';
import { basPositionPosLstData } from '/@/api/bas/pos/basPosition';


const { t } = useI18n('sys.empUser');

const modalProps = {
  title: t('货位选择'),
};

const searchForm: FormProps = {
  showResetButton: false,
  baseColProps: { lg: 6, md: 8 },
  labelWidth: 100,
  schemas: [
    {
      label: t('货位编码'),
      field: 'posCode',
      component: 'Input',
    },
    {
      label: t('货位名称'),
      field: 'posName',
      component: 'Input',
    },
    {
      label: t('仓库编码'),
      field: 'whcode',
      component: 'Input',
      show: false, // 隐藏字段，仅用于传递参数
    },
  ],
};

const tableColumns: BasicColumn[] = [
  {
    title: t('货位编码'),
    dataIndex: 'posCode',
    width: 100,
  },
  {
    title: t('货位名称'),
    dataIndex: 'posName',
    width: 100,
  },
  {
    title: t('仓库名称'),
    dataIndex: 'basWare.cwhname',
    width: 130,
  },
];

const tableProps: BasicTableProps = {
  api: basPositionPosLstData,
  beforeFetch: (params) => {
    console.log('posSelect beforeFetch params:', params);
    params['isAll'] = true;
    params['treeLeaf'] = '1';
    // 如果传入了仓库编码，则添加到查询参数中
    if (params.whcode) {
      // 将仓库编码传递给后端API
      console.log('设置仓库过滤条件:', params.whcode);
    }
    return params;
  },
  columns: tableColumns,
  formConfig: searchForm,
  rowKey: 'posCode',
};

export default {
  modalProps,
  tableProps,
  itemCode: 'posCode',
  itemName: 'posName',
  isShowCode: true,
};
